<template>
  <tl-sub-page :render="render" ref="drawerRef" :visible.sync="visible" :with-header="false" :modal-append-to-body="true" :close-on-press-escape="false" :append-to-body="true" class="tl-drawer editPage" :size="'95%'" @open="open" @close="close" :destroy-on-close="true">
    <div class="mpm-project-container">
      <div style="width:0px;overflow:hidden;height:0px;"><input type="text" /></div>
      <div class="mpm-project-header">
        <div class="info">
          <img src="/static/images/paojectManager/mpm_review_edit.png" class="logo" style="width: 55px;height: 55px" />
          <div class="content" :title="model.projectname">
            <p>
              <b v-if="model.id || projectinfo.projectcode">{{ model.projectname + '-' }}</b>
              <b>项目复盘</b>
            </p>
            <p class="light">
              <span>项目经理：{{ model.applyusername ? model.applyusername + '【' + model.applyusercode + '】' : user.name + '【' + user.code + '】' }}</span>
              <span v-if="model.createon">创建时间：{{ formatDate(model.createon) }}</span>
            </p>
          </div>
        </div>
        <div class="toolbar">
          <el-button type="danger" icon="el-icon-close" circle @click="doCancelEdit"></el-button>
        </div>
      </div>
      <div class="mpm-project-nav" :style="{ height: mainHeight + 'px' }">
        <ul class="nav-list">
          <template v-for="item in navList">
            <li :key="item.code" :class="item.on ? 'on' : ''" @click="clickNav(item.code)" style="cursor: pointer;clear: both">
              <span style="float: left;width: 150px">{{ item.name }}</span>
              <span style="float: left;">
                <i v-if="item.count > 0">{{ item.count }}</i>
                <label v-if="item.flag">{{ item.flag }}</label>
              </span>
            </li>
          </template>
        </ul>
      </div>
      <div class="mpm-project-main" :style="{ height: mainHeight + 'px' }">
        <el-scrollbar class="mpm-project-main-container" id="mpmMainContainer">
          <div style="padding:0 10px">
            <el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="150px" :disabled="disableEditSubmit || disableSave">
              <a id="basic" class="step-position">&nbsp;</a>
              <div class="tl-form-line-title">
                基本信息
              </div>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="项目" prop="projectname" :required="true" :rules="rules.validateRequire">
                    <el-input v-model="model.projectname" :disabled="true" class="tl-ref-selector">
                      <el-button slot="append" type="primary" icon="el-icon-search" @click="openmpmProjectRefDialog" v-if="!disableEditSubmit && !disableSave"></el-button>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="项目编号" prop="projectcode">
                    <el-input v-model="model.reviewcode" :disabled="true" placeholder="系统自动生成"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="Owner" prop="ownercode" :rules="rules.validateRequire">
                    <tl-ref-user v-model="model.ownercode" :initDisplayData.sync="model.owner" :disabled="true" dataType="code" :singleSelect="true"> </tl-ref-user>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="项目经理" prop="applyusercode" :rules="rules.validateRequire">
                    <tl-ref-user v-model="model.applyusercode" :initDisplayData.sync="model.applyusername" :disabled="true" dataType="code" :singleSelect="true"> </tl-ref-user>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="结项类型" prop="endtype" :rules="rules.validateRequire">
                    <el-select v-model="model.endtype" filterable clearable @change="clear()" :disabled="true">
                      <el-option v-for="item in codeModel.endtypeList" :key="item.code" :label="item.name" :value="item.code" />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="结项时间" prop="enddate" :rules="rules.validateRequire">
                    <el-date-picker v-model="model.enddate" type="date" placeholder="例：2021-01-01" value-format="yyyy-MM-dd" @change="judgeEndDate"></el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="是否中标" prop="iswinbid" :rules="rules.validateRequire">
                    <el-select v-model="model.iswinbid" filterable clearable @change="selectiswinbid">
                      <el-option v-for="item in codeModel.iswinbidList" :key="item.code" :label="item.name" :value="item.code" />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="结项金额" prop="settlementmoney" :rules="rules.validateRequire">
                    <el-input-number v-model="model.settlementmoney" controls-position="right" :step="1" :min="0" :precision="2" class="unitInputNumber" :disabled="settlementmoneyable" @click.native="clicksettlementmoney"></el-input-number>
                    <span class="unitSpan">万元</span>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="项目成果" prop="achievements">
                    <el-input v-model="model.achievements" type="textarea" :rows="4" maxlength="1000" show-word-limit></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="结项说明" prop="projectdescription">
                    <el-input v-model="model.projectdescription" type="textarea" :rows="4" maxlength="1000" show-word-limit></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="项目概述" prop="summary" :rules="rules.validateRequire">
                    <el-input v-model="model.summary" type="textarea" :rows="4" maxlength="1000" show-word-limit placeholder="简述项目整体情况，包括从信息获取到项目立项、执行、结果等过程节点"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <a id="result" class="step-position">&nbsp;</a>
              <div class="tl-form-line-title">
                项目结果
              </div>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="计划目标" prop="planningtarget" :rules="rules.validateRequire">
                    <el-input v-model="model.planningtarget" type="textarea" :rows="4" maxlength="1000" show-word-limit></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="实际结果" prop="actualresult" :rules="rules.validateRequire">
                    <el-input v-model="model.actualresult" type="textarea" :rows="4" maxlength="1000" show-word-limit></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="差异分析" prop="differenceanalysis" :rules="rules.validateRequire">
                    <el-input v-model="model.differenceanalysis" type="textarea" :rows="4" maxlength="1000" show-word-limit></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="备注" prop="description">
                    <el-input v-model="model.description" type="textarea" :rows="4" maxlength="1000" show-word-limit></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <a id="biddetail" class="step-position">&nbsp;</a>
              <div class="tl-form-line-title">
                评分细则
              </div>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="是否获取评分细则" prop="whetherbiddetails">
                    <el-select v-model="haveBidScoreData" filterable clearable disabled>
                      <el-option v-for="item in codeModel.whetherbiddetailsList" :key="item.code" :label="item.name" :value="item.code" />
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24" v-show="haveBidScoreData === '1'">
                  <mpm-project-bid-score-ref ref="bidScore1" :times="'3'" :editdisabled="!disableSave" :type="'1'" :projectinfo="projectinfo" :title="'商务'" :fromReview="true" @haveBidScore="haveBidScore"></mpm-project-bid-score-ref>
                  <mpm-project-bid-score-ref ref="bidScore2" :times="'3'" :editdisabled="!disableSave" :type="'2'" :projectinfo="projectinfo" :title="'技术'" :fromReview="true" @haveBidScore="haveBidScore"></mpm-project-bid-score-ref>
                  <tl-offer :ref="'line5'" :times="'3'" :editable="!disableSave" :type="'3'" :projectinfo="projectinfo" :title="'报价'" :showgapanalysis="true"></tl-offer>
                </el-col>
              </el-row>
              <a id="winbid" class="step-position">&nbsp;</a>
              <el-form :disabled="disableEditSubmit || disableSave">
                <mpm-project-win-bid-info-ref ref="winBidInfoRef" @saveAndOpenWinBidInfoDialog="saveAndOpenWinBidInfoDialog" :disableSave="disableSave" :projectcode="model.projectcode" :reviewid="model.id" :model="model"></mpm-project-win-bid-info-ref>
              </el-form>
              <a id="processAnalysis" class="step-position">&nbsp;</a>
              <div class="tl-form-line-title">
                项目过程分析
              </div>
              <el-row>
                <el-col :span="18">
                  <el-form-item label="里程碑及任务总结" :rules="rules.validateRequire"> </el-form-item>
                </el-col>
                <el-col :span="6">
                  <div class="text-hover" style="float: right;fontSize: 14px;margin: 6px" @click="openProcessAnalyse">全屏展示</div>
                </el-col>
              </el-row>
              <el-form :disabled="false">
                <mpm-project-milepost-ref style="margin-bottom: 30px" ref="milePostRef" :model="model"  @fullScreen="openProcessAnalyse"></mpm-project-milepost-ref>
              </el-form>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="客户关系分析" prop="customerrelationanalysis" :rules="rules.validateRequire">
                    <el-input v-model="model.customerrelationanalysis" type="textarea" :rows="4" maxlength="1000" show-word-limit placeholder="分析我方的客户关系（客户决策链、关键客户关系、普遍客户关系、评标专家）运作情况：计划是什么？做了哪些动作？实际结果是什么？（要如何做来提升，策划动作是否做到位，识别的关键客户是否准确）"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="竞争对手分析" prop="competitoranalysis" :rules="rules.validateRequire">
                    <el-input v-model="model.competitoranalysis" type="textarea" :rows="4" maxlength="1000" show-word-limit placeholder="分析竞争对手的市场策略、关键动作，取长补短。竞争对手通过什么动作获得了支持，我们的缺失项是什么，怎么提升"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <a id="summary" class="step-position">&nbsp;</a>
              <div class="tl-form-line-title">
                项目经验和总结教训
              </div>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="客户关系" prop="customerrelation" :rules="rules.validateRequire">
                    <el-input v-model="model.customerrelation" type="textarea" :rows="4" maxlength="1000" show-word-limit></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="标前引导" prop="guidebeforebid" :rules="rules.validateRequire">
                    <el-input v-model="model.guidebeforebid" type="textarea" :rows="4" maxlength="1000" show-word-limit></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="制作并提交标书" prop="submitbidingdocument" :rules="rules.validateRequire">
                    <el-input v-model="model.submitbidingdocument" type="textarea" :rows="4" maxlength="1000" show-word-limit></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="项目管理" prop="projectmanagement" :rules="rules.validateRequire">
                    <el-input v-model="model.projectmanagement" type="textarea" :rows="4" maxlength="1000" show-word-limit></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <a id="apply" class="step-position">&nbsp;</a>
              <div class="tl-form-line-title">
                申请信息
              </div>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="申请部门" prop="applydeptname">
                    <tl-ref-dept v-model="model.applydeptcode" :initDisplayData.sync="model.applydeptname" :disabled="true" dataType="code" nameType="fullname" :singleSelect="true" :externalQueryParam="{ qry_enabled: 1 }"></tl-ref-dept>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="申请公司" prop="applyorgname">
                    <el-input v-model="model.applyorgname" :readonly="true" class="is-disabled"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="申请人姓名" prop="applyusername">
                    <tl-ref-user v-model="model.applyusername" :initDisplayData.sync="model.applyusername" :disabled="true" dataType="code" :singleSelect="true"></tl-ref-user>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="申请人工号" prop="applyusercode">
                    <el-input v-model="model.applyusercode" :readonly="true" class="is-disabled"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="单据日期" prop="docdate">
                    <el-date-picker v-model="model.docdate" type="date" placeholder="单据日期" value-format="yyyy-MM-dd" disabled></el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="提交时间" prop="submitdate">
                    <el-date-picker v-model="model.submitdate" type="date" placeholder="提交时间" value-format="yyyy-MM-dd" disabled></el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="审批流程" prop="flowid">
                    <el-input v-model="model.dispflowid" :readonly="true" class="is-disabled"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="状态" prop="state">
                    <el-input v-model="model.dispstate" disabled></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer" style="float:right;margin-top:10px">
              <el-button @click="doSubmitEdit" :loading="saveLoading" v-if="!disableEditSubmit" :disabled="disableSave" icon="el-icon-document-checked" type="primary">保存</el-button>
              <el-button @click="projectSubmit" :loading="submitLoading" v-if="!disableEditSubmit" :disabled="disableApproval" type="primary">
                <svg-icon icon-class="send" />提交审批
              </el-button>
              <tl-attachment ref="attachmentRef" sourceType="MpmProjectReview" :sourceId="model.id" :disabled="disableAttachment" :editable="stateEdit || this.uiOperateState === '3'">
                <el-button type="primary" :disabled="disableAttachment" icon="el-icon-paperclip" @click="$refs.attachmentRef.openUploadDialog()">{{ this.$refs.attachmentRef ? this.$refs.attachmentRef.btnTitle : '' }} [{{ this.$refs.attachmentRef ? (this.$refs.attachmentRef.fileList.length > 0 ? this.$refs.attachmentRef.fileList.length : this.$refs.attachmentRef.fileCount) : 0 }}] </el-button>
              </tl-attachment>
              <el-button @click="$refs.history.visible = true" :disabled="disableApprovalHistory" type="primary">
                <svg-icon icon-class="list" />审批历史
              </el-button>
              <el-button @click="doDelApproval" v-if="!disableEditSubmit" :disabled="disableDelApproval" type="primary">
                <svg-icon icon-class="undo" />审批退回
              </el-button>
            </div>
          </div>
        </el-scrollbar>
      </div>
    </div>
    <tl-approval-history ref="history" sourceType="MpmProjectReview" :sourceId="model.id" />
    <tlmpm-project-ref ref="mpmProjectRef" @confirm="getmpmProjectRefData" :isSingleSelect="true" :externalQueryParam="externalQueryParamForPool"></tlmpm-project-ref>
    <mpm-project-milepost-ref style="margin-bottom: 30px" ref="milePostDialogRef" :model="model" :render="'el-dialog'" :el-table-height="null" @refresh="refreshProcessAnalyse" :disabled="disableEditSubmit || disableSave"></mpm-project-milepost-ref>
  </tl-sub-page>
</template>

<script>
/** mixins */
import { mixin_approval_edit_edit } from '../../../mixins/mixin_approval_edit'
import { validateNull } from '@tapui/utils/validate'
/** 子组件 */
import tlmpmProjectRef from '@/views/mpm/mpmProject/refList'
import MpmProjectWinBidInfoRef from '../mpmProjectWinBidInfo/indexComp'
import MpmProjectMilepostRef from '../mpmProjectMilepost/indexComp'
import MpmProjectBidDetailRef from '../mpmProjectReviewBidDetail/indexComp'
import MpmProjectBidScoreRef from '../mpmProjectBidScore/indexFrame'
import tlOffer from '../mpmProjectBidScore/indexFrameOffer'
/** 工具类 */
import { putAction, getAction, postAction, deleteAction } from '@tapui/utils/http'
import { formatDate } from '@tapui/utils/date'
/** VUE配置 */
export default {
  mixins: [mixin_approval_edit_edit],
  components: { MpmProjectMilepostRef, MpmProjectWinBidInfoRef, tlmpmProjectRef, MpmProjectBidDetailRef, MpmProjectBidScoreRef, tlOffer },
  data() {
    return {
      moduleTitle: '项目复盘结项',
      urlPrefix: '/mpm/projectReview/',
      isQueryOnCreated: false,
      externalQueryParamForPool: {},
      settlementmoneyable: false,
      mainHeight: 1000,
      mainScrollElement: null,
      navList: [{ name: '基本信息', on: true, code: 'basic' }, { name: '项目结果', on: false, code: 'result' }, { name: '评标细则', on: false, code: 'biddetail' }, { name: '中标信息', on: false, code: 'winbid' }, { name: '项目过程分析', on: false, code: 'processAnalysis' }, { name: '项目经验和总结教训', on: false, code: 'summary' }, { name: '申请信息', on: false, code: 'apply' }],
      navList1: [{ name: '基本信息', on: true, code: 'basic' }, { name: '项目结果', on: false, code: 'result' }, { name: '评标细则', on: false, code: 'biddetail' }, { name: '中标信息', on: false, code: 'winbid' }, { name: '项目过程分析', on: false, code: 'processAnalysis' }, { name: '项目经验和总结教训', on: false, code: 'summary' }, { name: '申请信息', on: false, code: 'apply' }],
      navList2: [{ name: '基本信息', on: true, code: 'basic' }, { name: '项目结果', on: false, code: 'result' }, { name: '中标信息', on: false, code: 'winbid' }, { name: '项目过程分析', on: false, code: 'processAnalysis' }, { name: '项目经验和总结教训', on: false, code: 'summary' }, { name: '申请信息', on: false, code: 'apply' }],
      url: {
        // 额外的url
      },
      // 是否在保存成功后打开中标信息弹框
      openWinBidInfoFlag: false,
      // 是否保存成功后打开评标细则信息弹窗
      openBidDetailFlag: false,
      haveBidScoreData: '0'
    }
  },
  props: {
    // 当前元素展示方式。默认为dialog，可选div/el-drawer
    render: {
      default: 'el-drawer',
      type: String
    },
    projectinfo: {
      type: Object,
      default: function () {
        return {}
      }
    }
  },
  computed: {
    // 禁用审批按钮
    disableApproval() {
      return (this.stateApproval && this.model.state !== 2) || this.uiOperateState === 4
    }
  },
  methods: {
    openProcessAnalyse() {
      this.$refs.milePostDialogRef.open()
    },
    refreshProcessAnalyse() {
      this.$refs.milePostRef.doQuery()
    },
    haveBidScore(type) {
      if (this.haveBidScoreData === '1') {
        return
      }
      if ((this.$refs.bidScore1 && this.$refs.bidScore1.datas.length > 0) || (this.$refs.bidScore2 && this.$refs.bidScore2.datas.length > 0)) {
          this.haveBidScoreData = '1'
        } else {
          this.haveBidScoreData = '0'
        }
    },
    async doSubmitEdit() {
      if (!this.beforeSubmit()) {
        return
      }
      if (this.isAdd) {
        this.doAdd()
      } else {
        this.doEdit()
      }
    },
    async projectSubmit() {
      let that = this
      that.submitLoading = true
      that.$refs.form.validate(async (valid, res) => {
        if (valid) {
          let saveresult = await that.addBase()
          if (saveresult) {
            if (!this.beforeApproval()) {
              this.submitLoading = false
              this.saveLoading = false
              return
            }
            this.submitLoading = true
            this.saveLoading = true
            const parameter = { id: that.model.id }
            putAction(that.url.submit, that.model)
              .then((res) => {
                if (res.success) {
                  that.queryData(that.model.id).then((_) => {
                    that.loaded()
                    that.saveLoading = false
                    that.submitLoading = false
                  })
                  that.$tap.alert('提交审批成功', 'success')
                } else {
                  that.$tap.alert(res.message, 'warning')
                  that.saveLoading = false
                  that.submitLoading = false
                }
              })
              .catch((err) => {
                that.saveLoading = false
                that.submitLoading = false
              })
          }
        } else {
          that.submitLoading = false
          that.$tap.alert('按要求填写表单数据项，包括必填项，数据格式等')
        }
      })
    },
    /** 抽屉组件必有 **/
    resizeHandler() {
      this.mainHeight = document.body.getBoundingClientRect().height - 100 - (this.isApproval ? 110 : 0)
    },
    /** 抽屉组件必有 **/
    doCancelEdit() {
      this.visible = false
      this.$emit('close')
      this.$emit('refresh')
      this.haveBidScoreData = '0'
    },
    /** 抽屉组件必有 **/
    formatDate(date) {
      return formatDate(new Date(date ? date.toString().replace(/\-/g, "/") : date), "yyyy-MM-dd")
    },
    /** 点击左侧导航，抽屉组件必有 **/
    clickNav(code) {
      this.navList.forEach((m) => {
        if (m.code === code) {
          m.on = true
        } else {
          m.on = false
        }
      })
      let element = document.getElementById(code)
      if (element === null) return
      let goY = element.getBoundingClientRect().y - 75
      this.mainScrollElement.scrollTop += goY
    },
    /** 页面滚动时，动态改变左侧导航选中的元素，抽屉组件必有 **/
    onMainScroll() {
      this.mainScrollElement.addEventListener('scroll', () => {
        let currentTop = this.mainScrollElement.scrollTop
        let code = ''
        for (let element of document.getElementsByClassName('step-position')) {
          if (element.getBoundingClientRect().y >= 0) {
            code = element.id
            break
          }
        }
        this.navList.forEach((m) => {
          if (m.code === code) {
            m.on = true
          } else {
            m.on = false
          }
        })
      })
    },
    /** 抽屉组件必重写，主要为了执行resizeHandler方法、给mainScrollElement赋值，并添加监听事件，不要直接复制该方法 **/
    open() {
      this.model = {}
      this.resizeHandler()
      this.$nextTick(() => {
        this.$refs.form.clearValidate()
        if (this.isAdd === true) {
          this.title = '新增' + this.moduleTitle
          // 需要添加重复判断
          if (this.$store.getters.param.isAvoidRepeat === true) {
            this.queryBillUid()
          }
          if (this.isQueryInitData === true) {
            // 后台进行数据初始化
            this.queryInitData().then((_) => {
              this.assignDefaultValue()
              this.loaded()
            })
          } else {
            // 前台进行数据初始化
            this.$set(this.model, 'enabled', 1)
            this.$set(this.model, 'sortcode', 0)
            this.assignDefaultValue()
            this.loaded()
          }
          // 判断是否可以将项目信息自动填写在单据中
          if (this.projectinfo.id) {
            this.getmpmProjectRefData(this.projectinfo)
          }
        } else if (this.disableEditSubmit === false) {
          this.title = '编辑' + this.moduleTitle
          this.queryData(this.id).then((_) => {
            this.$refs.form.clearValidate()
            this.loaded()
          })
        } else {
          this.title = '查看' + this.moduleTitle
          this.queryData(this.id).then((_) => {
            this.$refs.form.clearValidate()
            this.loaded()
          })
        }
        this.mainScrollElement = document.getElementById('mpmMainContainer').getElementsByClassName('el-scrollbar__wrap')[0]
        this.onMainScroll()
      })
    },
    clicksettlementmoney() {
      const { iswinbid } = this.model
      if (!iswinbid) {
        this.$tap.alert('请先选择是否中标！', 'warning')
        this.$set(this.model, 'settlementmoney', '')
      }
    },
    selectiswinbid() {
      const { iswinbid } = this.model
      this.settlementmoneyable = false
      if (iswinbid === '1') {
        this.settlementmoneyable = true
        this.$set(this.model, 'settlementmoney', 0)
        this.$emit('refresh')
      }
    },
    /** 打开项目参照 */
    openmpmProjectRefDialog() {
      const { applyusercode } = this.model
      this.externalQueryParamForPool = { qry_projectmanagercode: applyusercode, qry_projectstate: 1 }
      this.$refs.mpmProjectRef.visible = true
    },
    /** 获取项目参数数据 */
    getmpmProjectRefData(selectionRow, selectKey, selectionValue) {
      this.$set(this.model, 'projectid', selectionRow.id)
      this.$set(this.model, 'projectname', selectionRow.projectname)
      this.$set(this.model, 'projectcode', selectionRow.projectcode)
      this.$set(this.model, 'deptcode', selectionRow.deptcode)
      this.$set(this.model, 'owner', selectionRow.owner)
      this.$set(this.model, 'ownercode', selectionRow.ownercode)
      this.$set(this.model, 'projectplanstartdate', selectionRow.planstartdate)
      this.$set(this.model, 'deptcommoncode', selectionRow.deptcommoncode)
      this.aftergetproject()
    },
    aftergetproject() {
      const { projectid, projectcode } = this.model
      // this.endtypeable = false
      this.$set(this.model, 'endtype', '')
      var params = {
        qry_projectcode: projectcode
      }
      getAction('/mpm/projectReview/judegEndTpye', params).then((res) => {
        if (res.success) {
          if (res.result.endtype === '1') {
            this.$tap.alert('该项目下有未完成的里程碑及任务和任务，或没有已完成的里程碑及任务，只能异常结项！')
            this.$set(this.model, 'endtype', '1')
          } else {
            this.$set(this.model, 'endtype', '0')
          }
          this.$set(this.model, 'purchasepattern', res.result.purchasepattern)
        } else {
          this.$tap.alert(res.message, 'warning')
        }
      })
      // 刷新里程碑及任务表格
      this.$set(this.projectinfo, 'projectcode', this.model.projectcode)
      this.$refs.milePostRef.doQuery()
      this.$refs.bidScore1.doQuery()
      this.$refs.bidScore2.doQuery()
    },
    assignDefaultValue() {
      if (this.isAdd) {
        this.$set(this.model, 'docdate', new Date())
        this.$set(this.model, 'applyusername', this.user.name)
        this.$set(this.model, 'applyusercode', this.user.code)
        this.$set(this.model, 'applydeptcode', this.dept.code)
        this.$set(this.model, 'applydeptname', this.dept.fullname)
        this.$set(this.model, 'applyorgcode', this.org.code)
        this.$set(this.model, 'applyorgname', this.org.name)
        this.$set(this.model, 'usercode', this.user.code)
        this.$set(this.model, 'username', this.user.name)
        // this.$set(this.model, 'deptcode', this.dept.code)
      }
    },
    loaded() {
      // 页面加载完毕执行
      if (!this.isAdd && this.model.docno) {
        this.title = this.title + `（单据编号：${this.model.docno}）`
      }
      // 加载中标信息
      if (this.model.id) {
        this.$refs.winBidInfoRef.doQuery()
      }
      // 加载里程碑及任务信息和评分细则信息
      if (this.model.projectcode) {
        this.$set(this.projectinfo, 'projectcode', this.model.projectcode)
        this.$refs.milePostRef.doQuery()
        this.$refs.bidScore1.doQuery()
        this.$refs.bidScore2.doQuery()
      }
      // 若为不可编辑状态则清空placeholder
      if (this.disableEditSubmit || this.disableSave) {
        this.$refs.form.fields.forEach((item) => {
          if (item.$children[1].$options._componentTag === 'el-input') {
            item.$children[1].getInput().placeholder = ''
          }
        })
      }
    },
    beforeApproval() {
      if (this.model.endtype === '0') {
        if (this.model.iswinbid === '0' && this.$refs.attachmentRef.fileCount <= 0 && this.$refs.attachmentRef.fileList.length <= 0) {
          this.$tap.alert('请上传中标通知书或合同扫描件！', 'warning')
          this.submitLoading = false
          return false
        } else if (this.model.iswinbid === '1' && this.$refs.attachmentRef.fileCount <= 0 && this.$refs.attachmentRef.fileList.length <= 0) {
          this.$tap.alert('请上传中标公告截图！', 'warning')
          this.submitLoading = false
          return false
        }
      }
      // 评分细则存在
      if (this.haveBidScoreData === '1') {
        if (!validateNull(this.$refs.bidScore1.datas) && this.$refs.bidScore1.datas.length > 0) {
          let tempData = this.$refs.bidScore1.datas
          for (let temp in tempData) {
            if (validateNull(tempData[temp].feedbackscore) || validateNull(tempData[temp].losspointandadvice)) {
              this.$tap.alert('评标细则-商务须填写专家反馈得分、失分点及改进意见！', 'warning')
              this.submitLoading = false
              return false
            }
          }
        }
        if (!validateNull(this.$refs.bidScore2.datas) && this.$refs.bidScore2.datas.length > 0) {
          let tempData = this.$refs.bidScore2.datas
          for (let temp in tempData) {
            if (validateNull(tempData[temp].feedbackscore) || validateNull(tempData[temp].losspointandadvice)) {
              this.$tap.alert('评标细则-技术须填写专家反馈得分、失分点及改进意见！', 'warning')
              this.submitLoading = false
              return false
            }
          }
        }
      }
      // 将是否存在评标细则赋值到this.model上
      this.$set(this.model, 'havebidscoredata', this.haveBidScoreData)
      return true
    },
    /** PMO标准化 **/
    async saveInfo(resolve, reject) {
      this.$refs.form.validate((valid) => {
        if (valid) {
          putAction(this.url.edit, this.model)
            .then((res) => {
              if (res.success) {
                this.$emit('refresh')
                resolve()
              } else {
                this.$tap.alert(res.message, 'warning')
                reject()
              }
            })
            .catch((err) => {
              this.$tap.alert('修改项目信息失败，请联系系统管理员', 'warning')
              reject()
            })
        } else {
          this.$tap.alert('请填写所有必填字段!', 'warning')
          reject()
        }
      })
    },
    /** 保存成功后打开中标信息弹框 **/
    saveAndOpenWinBidInfoDialog() {
      // 将openWinBidInfoFlag置为true
      this.openWinBidInfoFlag = true
      this.doSubmitEdit()
    },
    saveAndOpenBidDetailDialog() {
      this.openBidDetailFlag = true
      this.doSubmitEdit()
    },
    /** 提交前执行 */
    beforeSubmit() {
      if (!this.model.projectname) {
        this.$tap.alert('项目不能为空!', 'warning')
        return false
      } else {
        return true
      }
    },
    /** 重写执行新增提交，为了获取id */
    doAdd() {
      this.saveLoading = true
      // 增加唯一单号
      this.$set(this.model, 'billuid', this.uid)
      postAction(this.url.add, this.model)
        .then((res) => {
          if (res.success) {
            this.$tap.message('添加成功', 'success')
            // 保证在刷新数据后再打开中标详情页
            this.queryData(res.result.id).then(() => {
              this.afterSubmit()
            })
            this.isAdd = false
          } else {
            this.$tap.alert(res.message, 'warning')
          }
          this.saveLoading = false
        })
        .catch((err) => {
          this.saveLoading = false
        })
    },
    afterSubmit() {
      if (this.openWinBidInfoFlag) {
        this.$refs.winBidInfoRef.openAddDialog('editForm')
        this.openWinBidInfoFlag = false
      }
      // if (this.openBidDetailFlag) {
      //   this.$refs.bidDetailRef.openAddDialog('editForm')
      //   this.openBidDetailFlag = false
      // }
      this.$refs.form.clearValidate()
    },
    /** 重写提交审批,进行表单校验 */
    doMultiApproval() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          if (this.isAdd) {
            this.doSaveAndApproval()
          } else {
            this.doSubmitApproval()
          }
        } else {
          return false
        }
      })
    },
    /** 执行新增保存和审批 */
    doSaveAndApproval() {
      this.saveLoading = true
      // 增加唯一单号
      this.$set(this.model, 'billuid', this.uid)
      postAction(this.url.add, this.model)
        .then((res) => {
          if (res.success) {
            this.$tap.message('添加成功', 'success')
            if (!this.url.load) {
              this.saveloading = false
              this.$tap.alert('请设置load地址!', 'warning')
              return
            }
            getAction(this.url.load, { id: res.result.id }).then((res) => {
              if (res.success) {
                this.model = res.result
                this.isAdd = false
                this.afterSubmit()
                this.doSubmitApproval()
              } else {
                this.$tap.alert(res.message, 'warning')
              }
            })
          } else {
            this.saveLoading = false
            this.$tap.alert(res.message, 'warning')
          }
        })
        .catch((err) => {
          this.saveLoading = false
        })
    },
    doSubmitApproval() {
      if (!this.url.submit) {
        this.$tap.alert('请设置审批地址!', 'warning')
        this.saveLoading = false
        return
      }
      this.submitLoading = true
      this.$tap
        .confirm('确定提交审批吗？提交后，单据内容不可修改！')
        .then((_) => {
          if (!this.beforeApproval()) {
            this.submitLoading = false
            this.saveLoading = false
            return
          }
          putAction(this.url.submit, this.model).then((res) => {
            if (res.success) {
              this.$tap.message(res.message, 'success')
              this.queryData(this.model.id)
              this.afterApproval()
            } else {
              this.$tap.alert(res.message, 'warning')
            }
            this.saveLoading = false
            this.submitLoading = false
          })
        })
        .catch((_) => {
          this.saveLoading = false
          this.submitLoading = false
        })
    },
    judgeEndDate(e) {
      var enddate = new Date(this.model.enddate).getTime()
      var planstartdate = new Date(this.model.projectplanstartdate).getTime()
      if (enddate < planstartdate) {
        this.$tap.alert('项目结项时间不得早于项目计划开始时间', 'warning')
        this.model.enddate = null
        return
      }
    }
  },
  created() {
    window.addEventListener('resize', this.resizeHandler)
  },
  destroyed() {
    window.removeEventListener('resize', this.resizeHandler)
  }
}
</script>
<style lang="scss" scoped>
  .text-hover:hover {
    color: #0A6ED2;
    cursor: pointer;
  }
</style>
